/* vim: set sw=4 ts=4 sts=4 expandtab: */
#include <e.h>
#include "config.h"
#include "e_mod_main.h"

struct _E_Config_Dialog_Data 
{
   unsigned char hist_len;
   unsigned char show_win;
};

/* Local Function Prototypes */
static void *_create_data(E_Config_Dialog *cfd);
static void _free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
static void _fill_data(E_Config_Dialog_Data *cfdata);
static Evas_Object *_basic_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata);
static int _basic_apply(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);

/* External Functions */
EAPI E_Config_Dialog *
e_int_config_oplist_module(E_Container *con) 
{
    E_Config_Dialog *cfd = NULL;
    E_Config_Dialog_View *v = NULL;
    char buf[4096];

    /* is this config dialog already visible ? */
    if (e_config_dialog_find("Oplist", "_e_module_places_cfg_dlg"))
        return NULL;

    v = E_NEW(E_Config_Dialog_View, 1);
    if (!v)
        return NULL;

    v->create_cfdata = _create_data;
    v->free_cfdata = _free_data;
    v->basic.create_widgets = _basic_create;
    v->basic.apply_cfdata = _basic_apply;

    /* Icon in the theme */
    snprintf(buf, sizeof(buf), "%s/e-module-oplist.edj",
                                            oplist_conf->module->dir);

    /* create new config dialog */
    cfd = e_config_dialog_new(con, D_("Oplist Configuration"), "Oplist", 
                             "_e_module_oplist_cfg_dlg", buf, 0, v, NULL);
    oplist_conf->cfd = cfd;
    return cfd;
}

/* Local Functions */
static void *
_create_data(E_Config_Dialog *cfd) 
{
    E_Config_Dialog_Data *cfdata = NULL;

    cfdata = E_NEW(E_Config_Dialog_Data, 1);
    _fill_data(cfdata);
    return cfdata;
}

static void 
_free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata) 
{
    oplist_conf->cfd = NULL;
    E_FREE(cfdata);
}

static void 
_fill_data(E_Config_Dialog_Data *cfdata) 
{
    /* load a temp copy of the config variables */
    cfdata->show_win = oplist_conf->show_win;
    cfdata->hist_len = oplist_conf->hist_len;
}

static Evas_Object *
_basic_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata) 
{
    Evas_Object *o, *of, *ob;

    o = e_widget_list_add(evas, 0, 0);

    of = e_widget_framelist_add(evas, D_("General"), 0);
    e_widget_framelist_content_align_set(of, 0.0, 0.0);

    ob = e_widget_check_add(evas, D_("Show EFM window on item click"),
                                                    &(cfdata->show_win));
    e_widget_framelist_object_append(of, ob);

    ob = e_widget_slider_add(evas, 1, 0, D_("%d items"), 0, 100, 1, 0, NULL,
                                        &(cfdata->hist_len), 200);
    e_widget_framelist_object_append(of, ob);

   return o;
}

static int 
_basic_apply(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata) 
{
   oplist_conf->hist_len = cfdata->hist_len;
   oplist_conf->show_win = cfdata->show_win;

   e_config_save_queue();
   oplist_update_all_gadgets();
   return 1;
}
